﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LSBLL;
using LSEntity;
using LSUtility;
using OralExamBLL;
using OralExamEntity;

namespace LSWeb.Areas.OralExam.Controllers
{
    public class LoginController : ControllerCommon<OEControllerFormat<OEControllerFormatBLL, OECommonNone>, OEControllerCheck, OECommonNone>
    {
        //
        // GET: /OralExam/Login/

        [HttpGet]
        public ActionResult Index(string url = null)
        {
            return View(new OELogin
                            {
                                IsAsyn = false,
                                ReturnUrl =
                                    String.IsNullOrEmpty(url)
                                        ? HttpUtility.UrlEncode(HttpContext.Request.UrlReferrer.Obj2Str())
                                        : url
                            });
        }

        [HttpPost]
        public ActionResult Index(LoginConfig model)
        {
            MemberEntity member;
            var result = MemberBLL.Login<OELoginBLL>(model, out member);
            if (model.IsAsyn)
            {
                return new JsonResult
                {
                    Data = ResultMessage<int, String>.ResultMessageJson(result ? 1 : 0, result ? "成功" : "失败")
                };
            }
            return Redirect(HttpUtility.UrlDecode(model.ReturnUrl));
        }

        public ActionResult LoginOff()
        {
            MemberBLL.LoginOff<OELoginBLL>();
            var url = HttpContext.Request.UrlReferrer;
            return Redirect(url == null ? "~/" : url.AbsoluteUri);
        }
    }
}
